//* "/post msg": associate "msg" with an id 'msgid', put it into a global buffer, 
//    and then broadcast to others the following message.
//    Student1> /post This is a test. 
//    Student1 post a msg '101': "This is a test". 
//    Note that the server broadcasts the message "/post Student1 101 This is a test.". 

package server;
import java.net.*;
import java.io.*;
import java.util.*;


class post extends ChatFormat
{
	public post(String line)
	{
		super(line);
	}

	public void execute(KKMultiServerThread server)
	{

		int new_id = server.add_msg_queue(server.getUser(),msg);
		
		Set set = KKMultiServerThread.getChatMap().entrySet();
		Iterator It = set.iterator();
		
		int n=0;
		while (It.hasNext()) {
			Map.Entry me = (Map.Entry)It.next();
			PrintWriter out = ( (KKMultiServerThread.ChatIO) me.getValue() ).out;
			String name = server.getUser();
			//out.println(name + " post a msg '" + new_id + "':" + "\"" +  msg + "\".");
        //Student1 post a msg '101': "This is a test".
        //Note that the server broadcasts the message "/post Student1 101 This is a test.".
			server.send_post_client(out, name + " " + new_id + " " + msg );
		}

	}
}
